/*
 * @Author: szx
 * @Date: 2022-03-07 14:28:58
 * @LastEditTime: 2022-03-07 14:28:59
 * @Description: 
 * @FilePath: \leetcode\200-299\235\235_2.js
 */
var lowestCommonAncestor = function (root, p, q) {
    if (!root) return null;
    if ((root.val <= p.val && root.val >= q.val) || (root.val >= p.val && root.val <= q.val)) return root;
    if (root.val > p.val && root.val > q.val) return lowestCommonAncestor(root.left, p, q);
    if (root.val < p.val && root.val < q.val) return lowestCommonAncestor(root.right, p, q);
};